from app.customer.models import Customer
from app.expertise.models import Expertise
from app.expert.crud import Expert
from app.expertise.schemas import ExpertiseCreate, ExpertiseUpdate
from app.crud import CRUDBase

from typing import Optional


class CRUDExpertise(CRUDBase[Expertise, ExpertiseCreate, ExpertiseUpdate]):
    async def create(self, schema: ExpertiseCreate) -> Optional[Expertise]:
        get_expert = await Expert.objects.get_or_none(pk=schema.expert_id)
        get_customer = await Customer.objects.get_or_none(pk=schema.customer_id)
        if not(get_customer and get_expert):
            return None
        return await super().create(schema)


expertise = CRUDExpertise(Expertise)
